<template>
  <div class="start-node">
    <!-- 删除按钮 -->
    <el-button 
      class="delete-btn" 
      size="small" 
      type="danger" 
      circle
      @click.stop="handleDelete"
    >
      <el-icon><Close /></el-icon>
    </el-button>
    
    <div class="node-header">
      <el-icon class="node-icon"><VideoPlay /></el-icon>
      <span class="node-title">{{ data.label }}</span>
    </div>
    <div class="node-content">
      <span class="node-description">流程开始</span>
    </div>
    
    <!-- 输出连接点 -->
    <Handle
      type="source"
      position="bottom"
      class="custom-handle source-handle"
    />
  </div>
</template>

<script setup>
import { Handle } from '@vue-flow/core'
import { VideoPlay, Close } from '@element-plus/icons-vue'
import { ElMessageBox, ElMessage } from 'element-plus'

const props = defineProps({
  data: {
    type: Object,
    required: true
  },
  id: {
    type: String,
    required: true
  }
})

const emit = defineEmits(['delete'])

// 处理删除节点
const handleDelete = () => {
  ElMessageBox.confirm(
    '确定要删除这个开始节点吗？此操作不可撤销。',
    '删除节点',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    emit('delete', { id: props.id, ...props })
    ElMessage.success('节点已删除')
  }).catch(() => {
    // 用户取消删除
  })
}
</script>

<style scoped>
.start-node {
  background: linear-gradient(135deg, #67c23a, #85ce61);
  color: white;
  border-radius: 12px;
  padding: 12px 16px;
  min-width: 120px;
  box-shadow: 0 4px 12px rgba(103, 194, 58, 0.3);
  position: relative;
}

.node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.node-icon {
  font-size: 16px;
}

.node-title {
  font-weight: 600;
  font-size: 14px;
}

.node-content {
  font-size: 12px;
  opacity: 0.9;
}

.node-description {
  color: rgba(255, 255, 255, 0.8);
}

.custom-handle {
  width: 12px;
  height: 12px;
  border: 2px solid white;
  background: #67c23a;
}

.source-handle {
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
}

.delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px !important;
  height: 20px !important;
  min-height: 20px !important;
  padding: 0 !important;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.start-node:hover .delete-btn {
  opacity: 1;
}

.delete-btn .el-icon {
  font-size: 12px;
}
</style>